﻿package frEngine.shader.filters.fragmentFilters
{
    import __AS3__.vec.*;
    import baseEngine.system.*;
    import frEngine.shader.*;
    import frEngine.shader.filters.*;

    public class FogFilter extends FilterBase
    {
        private var _minDistance:Number = 0;
        private var _maxDistance:Number = 1000;
        private var _fogColor:uint;
        private var _fogR:Number;
        private var _fogG:Number;
        private var _fogB:Number;
        private var fcFogColor:Vector.<Number>;
        private var fcFogDistance:Vector.<Number>;

        public function FogFilter(param1:Number, param2:Number, param3:uint = 8421504)
        {
            this.fcFogColor = this.Vector.<Number>([0, 1, 0, 1]);
            this.fcFogDistance = this.Vector.<Number>([0, 0.0004, 0, 0]);
            super(FilterType.FogFilter, FilterPriority.FogFilter);
            this.minDistance = param1;
            this.maxDistance = param2;
            this.fogColor = param3;
            return;
        }// end function

        public function get minDistance() : Number
        {
            return this._minDistance;
        }// end function

        public function set minDistance(param1:Number) : void
        {
            this._minDistance = param1;
            this.fcFogDistance[0] = this._minDistance;
            this.fcFogDistance[1] = 1 / (this._maxDistance - this._minDistance);
            return;
        }// end function

        public function get maxDistance() : Number
        {
            return this._maxDistance;
        }// end function

        public function set maxDistance(param1:Number) : void
        {
            this._maxDistance = param1;
            this.fcFogDistance[0] = this._minDistance;
            this.fcFogDistance[1] = 1 / (this._maxDistance - this._minDistance);
            return;
        }// end function

        public function get fogColor() : uint
        {
            return this._fogColor;
        }// end function

        public function set fogColor(param1:uint) : void
        {
            this._fogColor = param1;
            var _loc_2:* = (param1 >> 16 & 255) / 255;
            this._fogR = (param1 >> 16 & 255) / 255;
            this.fcFogColor[0] = _loc_2;
            var _loc_2:* = (param1 >> 8 & 255) / 255;
            this._fogG = (param1 >> 8 & 255) / 255;
            this.fcFogColor[1] = _loc_2;
            var _loc_2:* = (param1 & 255) / 255;
            this._fogB = (param1 & 255) / 255;
            this.fcFogColor[2] = _loc_2;
            return;
        }// end function

        override public function setRegisterParams(param1:Program3dRegisterInstance) : void
        {
            param1.getParamByName("{CamPos}", false).value = Global3D.scene.cpos;
            param1.getParamByName("{fcFogColor}", false).value = this.fcFogColor;
            param1.getParamByName("{fcFogDistance}", false).value = this.fcFogDistance;
            return;
        }// end function

        override public function dispose() : void
        {
            super.dispose();
            return;
        }// end function

        override public function get programeId() : String
        {
            return "FogFilter0";
        }// end function

        override public function clone() : FilterBase
        {
            return this;
        }// end function

        override public function createVertexCode(param1:Program3dRegisterInstance, param2:int) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("vf1", "{V_GloblePos}", false, 1));
            param1.toBuild("", _loc_3);
            return "";
        }// end function

        override public function createFragmentColor(param1:Program3dRegisterInstance, param2:Boolean) : String
        {
            var _loc_3:* = new Array();
            _loc_3.push(new ToBuilderInfo("fc0", "{CamPos}", false, 1, Global3D.scene.cpos));
            _loc_3.push(new ToBuilderInfo("fc1", "{fcFogColor}", false, 1, this.fcFogColor));
            _loc_3.push(new ToBuilderInfo("fc2", "{fcFogDistance}", false, 1, this.fcFogDistance));
            var _loc_4:* = "sub ft1,{V_GloblePos} ,{CamPos}  \n" + "mul ft1, ft1, ft1 \n" + "add ft1.w,ft1.x,ft1.y \n" + "add ft1.w,ft1.w,ft1.z \n" + "sqt ft1.z,ft1.w \n" + "sub ft2.w, ft1.z, {fcFogDistance}.x \n" + "mul ft2.w, ft2.w, {fcFogDistance}.y \n" + "sat ft2.w, ft2.w \n" + "sub ft1, {fcFogColor}, {output} \n" + "mul ft1, ft1, ft2.w \n" + "add {output}, {output}, ft1 \n" + "";
            _loc_4 = param1.toBuild(_loc_4, _loc_3);
            return _loc_4;
        }// end function

    }
}
